<?php

namespace App\Services;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;

class TronService
{
    protected $client;
    protected $apiUrl = 'https://apilist.tronscanapi.com';
    public function __construct()
    {
        $this->client = new Client();
    }

    public function getTransactions($address)
    {
        $url = $this->apiUrl . '/api/filter/trc20/transfers';

        $response = Http::get($url, [
                'limit'            => 10,               // 每次获取 20 条记录
                'start'            => 0,                // 从第 0 条记录开始
                'sort'             => '-timestamp',     // 按时间戳降序排序
                'filterTokenValue' => 0,                // 过滤转账金额为 0 的记录
                'relatedAddress'   => $address,         // 查询指定地址的转账记录
                'toAddress'        => $address
            ]);

        return $response->json();
    }
}
